package com.hzhc.controller.wxapp;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.common.BaseController;
import com.hzhc.dto.UserDto;
import com.hzhc.entity.YwOrderCntr;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.YwOrderCntrService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.YwOrderCntrVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 功不唐捐
 * @description app委托清单模块
 * @date 2024-06-19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/app")
public class WxApiYwOrderCntrController extends BaseController {

    private final YwOrderCntrService ywOrderCntrService;

    /**
     * 导入清单
     */
    @RequestMapping("/appCntrUpload/{orderNo}")
    public ResultUtil<List<YwOrderCntrVo>> cntrUpload(@PathVariable("orderNo")String orderNo , MultipartFile file) {
        return ywOrderCntrService.cntrUpload(orderNo,file);
    }

    /**
     * 导入清单
     */
    @RequestMapping("/appCntrUpload/{orderNo}/{type}")
    public ResultUtil<List<YwOrderCntrVo>> cntrUploadByType(@PathVariable("orderNo")String orderNo ,@PathVariable("type")String type , MultipartFile file, HttpServletRequest request) {
        UserDto user = TokenUtil.getUser(request);
        return ywOrderCntrService.cntrUpload(orderNo,type,file);
    }

    /**
     * 导入到达清单
     */
    @RequestMapping("/appCntrDdUpload/{orderNo}")
    public ResultUtil<List<YwOrderCntrVo>> cntrDdUpload(@PathVariable("orderNo")String orderNo , MultipartFile file, HttpServletRequest request) {
        UserDto user = TokenUtil.getUser(request);
        return ywOrderCntrService.cntrDdUpload(orderNo,file);
    }


    /**
     * 查询箱明细
     */
    @RequestMapping("/getYwOrderCntrList")
    public ResultUtil<List<YwOrderCntr>> getYwOrderCntrList(@RequestBody YwOrderCntrVo vo) {
        Page<YwOrderCntrVo> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
        List<YwOrderCntr> vos = ywOrderCntrService.getCntrList(page, vo);
        return ResultUtil.build(vos,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 查询
     */
    @RequestMapping("/getPowerCntrList")
    public ResultUtil<List<YwOrderCntrVo>> getPowerCntrList(@RequestBody YwOrderCntrVo vo) {
        Page<YwOrderCntrVo> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
        List<YwOrderCntrVo> vos = ywOrderCntrService.getPowerCntrList(page, vo);
        return ResultUtil.build(vos,page.getTotal(),page.getPages(),ResultUtilCodeEnum.SUCCESS);
    }

}
